from flask import render_template, json, request
from flask import Blueprint
from flask import url_for

main = Blueprint('main', __name__, template_folder='templates', static_folder='static', static_url_path="/static")


def getDict2Json(data=dict):
    jsonStr = json.dumps(data)
    jsonStr = jsonStr.replace('None', '')
    return jsonStr

@main.route('/', defaults={'path': ''})
@main.route('/<path:path>')
def index(path):
  return render_template('index.html')


@main.route('/getData')
def getData():
    data = request.args.to_dict()    
    data["errorCode"]=0
    data["errorMsg"]="get success"
    
    jsonStr = getDict2Json(data)
    
    return jsonStr

@main.route('/postData',methods=['POST'])
def postData():
    data={}
    # data = json.loads(request.get_data())
    
    data["errorCode"]=0
    data["errorMsg"]="post success"
    
    jsonStr = getDict2Json(data)
    
    return jsonStr